﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using SharedGenomics.Core;
using SharedGenomics.Domain;
using SharedGenomics.Annotations;
using SharedGenomics.Workbench.Annotations;

using Rhino.Mocks;

namespace SharedGenomics.Workbench.Tests.Annotations
{
    [TestClass]
    public class SnpAnnotationRepositoryTests
    {
        private List<AnnotationDescriptor> descriptors;

        [TestInitialize]
        public void Setup()
        {
            this.descriptors = new List<AnnotationDescriptor>
            {
                AnnotationDescriptor.GetDescriptorForKey(AnnotationKey.GoogleSearch),
                AnnotationDescriptor.GetDescriptorForKey(AnnotationKey.PubMedSearch)
            };
        }

        [TestMethod]
        public void ShouldCreateAnnotationSetsForSnps()
        {
            List<AnalysisResult> results = new List<AnalysisResult>
            {
                new FastEpistasisAnalysisResult { SnpName = "rs1", Snp2 = "rs2" },
                new FastEpistasisAnalysisResult { SnpName = "rs3", Snp2 = "RS2" },
                new FastEpistasisAnalysisResult { SnpName = "rs4", Snp2 = "Rs1" },
            };

            var repository = new SnpAnnotationRepository(results, this.descriptors);

            //there should be a result set for rs1-4
            Enumerable.Range(1, 4).Select(i => "rs" + i).ForEach(snp => Assert.IsNotNull(repository[snp]));
            Assert.AreEqual(4, repository.AnnotationSets.Count());
        }

        [TestMethod]
        public void AnnotationSetShouldBeNullIfNotFound()
        {
            AnalysisResult r1 = new FastEpistasisAnalysisResult { SnpName = "rs1", Snp2 = "rs2" };
            var repository = new SnpAnnotationRepository(r1.AsSingleton(), this.descriptors);

            Assert.IsNull(repository["notFound"]);
        }
    }
}
